import {
    msg,
    close,
    getQueryStringFromHash,
    confirm
} from '../../common/utils.js';
import Vue from 'vue';
import {
    serverPath,
    json
} from '../../common/config.js';
import ClientService from '../services/clientService.js';

window.Module = function () {
    let clientService = new ClientService();
    return new Vue({
        el: '#auditPageController',
        data: {
            entity: {

            }
        },
        methods: {
            init: async function () {
                let id = getQueryStringFromHash('id');
                if (!id)
                    close();
                let res = await clientService.getClientById(id);
                if (json == res.type) {
                    var response = res.body;
                    if ('Success' === response.result) {
                        this.entity = response.data;
                    }
                    else {
                        await msg(response.message);
                    }
                }
            },
            close: function () {
                close();
            },
            pass: async function (item) {
                if (!item)
                    return;
                await confirm(`确定要审核通过该会员(会员名称:${item.name})？`);
                let res = await clientService.pass(item.id);
                if (json === res.type) {
                    var response = res.body;
                    if ('Success' === response.result) {
                        this.close();
                    }
                    else {
                        await msg(response.message);
                    }
                }
            },
            noPass: async function (item) {
                if (!item)
                    return;
                await confirm(`确定要审核不通过该会员(会员名称:${item.name})？`);
                let res = await clientService.noPass(item.id);
                if (json === res.type) {
                    var response = res.body;
                    if ('Success' === response.result) {
                        this.close();
                    }
                    else {
                        await msg(response.message);
                    }
                }
            }
        }
    });
}